<?php
/**
 * Created by PhpStorm.
 * User: 65736
 * Date: 2019/4/8 0008
 * Time: 20:35
 */

namespace app\crontab\controller\swoole;
use app\crontab\controller\CrontabCommon;
use app\common\library\CommonFun;
use Kcloze\Jobs\Console;

class Jobs extends CrontabCommon
{
    public function index()
    {
        CommonFun::get_other_config("SwooleJobConfig",2);
        $config = config('swoole_job_config');
        $console = new Console($config);
        global $argv;
        if (empty($argv[4])) {
            $console->start();
            return;
        }
        $opt=$argv[4];
        switch ($opt) {
            case 'start':
                $console->start();
                break;
            case 'stop':
                $console->sendSignal();
                break;
            case 'status':
                $console->sendSignal(SIGUSR2);
                break;
            case 'exit':
                $console->kill();
                break;
            case 'restart':
                $console->restart();
                break;
            case 'help':
                $console->printHelpMessage();
                break;

            default:
                $console->printHelpMessage();
                break;
        }
    }

    public function index_mq()
    {
        CommonFun::get_other_config("SwooleJobMqConfig",2);
        $config = config('swoole_job_mq_config');
        $console = new Console($config);
        global $argv;
        if (empty($argv[4])) {
            $console->start();
            return;
        }
        $opt=$argv[4];
        switch ($opt) {
            case 'start':
                $console->start();
                break;
            case 'stop':
                $console->sendSignal();
                break;
            case 'status':
                $console->sendSignal(SIGUSR2);
                break;
            case 'exit':
                $console->kill();
                break;
            case 'restart':
                $console->restart();
                break;
            case 'help':
                $console->printHelpMessage();
                break;

            default:
                $console->printHelpMessage();
                break;
        }
    }
}